package akaram.util.dice.tests;

import akaram.util.dice.DiceThrow;
import akaram.util.dice.RollDiceException;
import junit.framework.TestCase;

public class DiceThrowTest extends TestCase {
	
	private DiceThrow dt;
	
	public void setUp()
	{
		dt = new DiceThrow(2,6,1);
	}

	public void testDiceThrowIntIntInt() {
		DiceThrow d = new DiceThrow(1,2,3);
	}

	public void testDiceThrowString() {
		try {
			DiceThrow d = new DiceThrow("hgsdsds");
			fail("An exception expected.");
		} catch (RollDiceException e) {
		}

		DiceThrow d = null;
		try {
			d = new DiceThrow("2d6+1");
		} catch (RollDiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		assertEquals("2d6+1", d.toString());

		try {
			d = new DiceThrow("d%+10");
		} catch (RollDiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		assertEquals("1d100+10", d.toString());
	}

	public void testGetNumber() {
		assertEquals(2, dt.getNumber());
	}

	public void testGetFaces() {
		assertEquals(6, dt.getFaces());
	}

	public void testGetPlus() {
		assertEquals(1, dt.getPlus());
	}

	public void testGetThrow() {
		for(int i=0; i<10000; i++)
		{
			int thr = dt.getThrow();
			assertTrue(thr<=13);
			assertTrue(thr>=3);
		}
	}

	public void testToString() {
		assertEquals("2d6+1", dt.toString());
	}

}
